//index.js
//获取应用实例
const app = getApp()
import store from "../../utils/factory"
let that = null;
import {
  addComment,
} from "../../utils/config"

Page({
  data: {
    content: "",
    index: null,
    level: null,
    remark: "",
    starList: [{
      index: 1,
      img: "../../images/unStar.png"
    }, {
      index: 2,
      img: "../../images/unStar.png"
    }, {
      index: 3,
      img: "../../images/unStar.png"
    }, {
      index: 4,
      img: "../../images/unStar.png"
    }, {
      index: 5,
      img: "../../images/unStar.png"
    }]
  },
  onLoad: function (e) {
    that = this
  },
  onShow() {
  },
  watchRemark(e) {
    this.setData({
      content: e.detail.value
    })
  },
  setStar(e) {
    let eIndex = e.currentTarget.dataset.index;
    let starList = that.data.starList;
    starList.map((item, index) => {
      if (index <= eIndex - 1) {
        item.img = "../../images/star.png"
      } else {
        item.img = "../../images/unStar.png"
      }
    })
    console.log("starList", starList)
    that.setData({
      level: eIndex,
      starList: starList
    })
  },
  addComment() {
    addComment({
      content: that.data.content,
      id: store.get("orderId"),
      level: that.data.level
    }).then(res => {
      wx.showModal({
        title: "温馨提示",
        content: '评价成功',
        showCancel: false, //是否显示取消按钮
        success: function (res) {
          wx.navigateBack({ //返回上一页面或多级页面
            delta: 1
          })
        },
      })
    })
  }
})